﻿using System;
using Grpc.AspNetCore.Server;
using K9Nano.RemoteServer;
using Microsoft.AspNetCore.Builder;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class RemoteServerExtensions
    {
        public static IGrpcServerBuilder AddGrpcServer(this IServiceCollection services)
        {
            return services.AddGrpc(options =>
            {
                options.Interceptors.Add<DefaultServerInterceptor>();
            });
        }

        public static void UseGrpcServer<TService>(this IApplicationBuilder app) where TService: class
        {
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGrpcService<TService>();
            });
        }
    }
}
